package com.vtc.session13;

import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Toast;

public class Dialog1Activity extends DialogFragment{
   
	String[] options = {"Music","Sport","Shopping","Travelling"};
	List<String> selectedItems = new ArrayList<String>();
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setTitle("Select Favorites:");
		builder.setMultiChoiceItems(options, null, new DialogInterface.OnMultiChoiceClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which, boolean isChecked) {
				if(isChecked){
					selectedItems.add(options[which]);
				}
				else{
					selectedItems.remove(options[which]);
				}				
			}
		});
		builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				String str="";
				for(String item:selectedItems){
					str+= item+">";
				}
				Toast.makeText(getActivity(), str, Toast.LENGTH_LONG).show();			
			}
		});
		builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				Toast.makeText(getActivity(), "Cancel ", Toast.LENGTH_LONG).show();
			}
		});		
		return builder.create();
	}
}
